﻿$(document).ready(function () {
    $("#DropDownListMainSectionlist").change(function () {
        var selsecid = $(this).find("option:selected").val();
        getFirstChildRec(selsecid, "spanChildSec");
    });
    $("#spanChildSec select").live("change", function () {
        var selsecid = $(this).find("option:selected").val();
        var selectText = $(this).find("option:selected").html();
        getChildRec(selsecid, "spanChildSec", $("#spanChildSec select").index(this));
        $("#ChangeSecHidden").val(selsecid);
        if (selectText == "请选择栏目") {
            $("#ReferSectionTitle").html("无");
        }
        else {
            $("#ReferSectionTitle").html(selectText);
        }
    });

    $("#ImageButtonOk").bind("click", function () {
        if ($("#CKBoxReferSection").is(":checked")) {
            if ($("#ChangeSecHidden").val() == "-1" || $("#ChangeSecHidden").val() == "") {
                alerttispage("请选择要引用的栏目", "2秒后自动关闭", "");
                return false;
            }
        }
    })
})

function getFirstChildRec(secid, domMainContain) {
    var selectpar = $("#" + domMainContain);
    selectpar.html("");

    if (secid == null || secid == -1) {
        return;
    }

    selectpar.append("<img src='../../sysCommon/sysImages/loading4.gif' id='childclassloadimgimg' />");
    $.post("/IHandler/GetChildSec.ashx?q=" + new Date().getTime(), {
        'secid': secid
    }, function (data) {
        $("#childclassloadimgimg").remove();
        if (data.success == true) {
            var seclist = data.seclist;

            if (seclist.length > 0) {
                var timeid = "classshowlist" + new Date().getTime();
                selectpar.append('<select id="' + timeid + '" class="childselectshowlist" style="margin:0px 0px 0px 10px;"></select>');
                selectpar.find("#" + timeid).append("<option value='-1' >请选择栏目</option>");
                for (var i = 0; i < seclist.length; i++) {
                    selectpar.find("#" + timeid).append("<option value='" + seclist[i].secid + "'>" + seclist[i].secname + "</option>");
                }
            }
        } else {
            alerttispage("错误信息：" + data.msg, "2秒后自动关闭", "");
        }
    }, 'json');
}
function getChildRec(secid, domMainContain, thisselindex) {
    var selectpar = $("#" + domMainContain);

    if (secid == null || secid == -1) {
        return;
    }

    if (thisselindex != null) {
        selectpar.find("select").each(function (index, dom) {
            if (index > thisselindex) {
                $(dom).remove();
            }
        });
    }

    selectpar.append("<img src='../../sysCommon/sysImages/loading4.gif' id='childclassloadimgimg' />");
    $.post("/IHandler/GetChildSec.ashx?q=" + new Date().getTime(), {
        'secid': secid
    }, function (data) {
        $("#childclassloadimgimg").remove();
        if (data.success == true) {
            var seclist = data.seclist;

            if (seclist.length > 0) {
                var timeid = "classshowlist" + new Date().getTime();
                selectpar.append('<select id="' + timeid + '" class="childselectshowlist" style="margin:0px 0px 0px 10px;"></select>');
                selectpar.find("#" + timeid).append("<option value='-1'>请选择栏目</option>");
                for (var i = 0; i < seclist.length; i++) {
                    selectpar.find("#" + timeid).append("<option value='" + seclist[i].secid + "'>" + seclist[i].secname + "</option>");
                }
            }
        } else {
            alerttispage("错误信息：" + data.msg, "2秒后自动关闭", "");
        }
    }, 'json');
}